<div class="fsh-rightPanel">
    <div class="layui-anim layui-anim-upbit">
        <div id="list_form" class="layui-form-item wx-search">
            <div class="layui-inline">
                <select name="status" class="layui-input">
                    <option value="">全部</option>
                    <option value="0">未读</option>
                    <option value="1">已读</option>
                </select>
            </div>
            <button class="layui-btn btn-primary" id="search">搜索</button>
        </div>
        <table id="list_table" class="layui-hide" lay-filter="mainList"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">发布新任务</button>
        <button class="layui-btn layui-btn-sm" lay-event="myTask">查看我的任务</button>
    </div>
</script>

<script>
    layui.use(['layer', 'table'], function () {
        var layer = layui.layer;
        var table = layui.table;
        var tableObj = table.render({
            elem: '#list_table'
            , url: context + '/api/eduTask/listMyPublish',
            //开启头部工具栏，并为其绑定左侧模板，
            toolbar: '#toolbarDemo'
            , request: {
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , align: 'center'
            , cols: [[ //表头
                // {type: 'checkbox', fixed: 'left'},
                {field: 'task_his_id', title: 'ID', align: 'center'},
                {field: 'title', title: '标题', align: 'center'},
                {field: 'type', title: '类型', align: 'center', templet: function (d) {
                    switch(d.type){case 1: return '课程任务'; case 2: return  '作业任务';case 3: return  '考试任务';default: return '';}}},
                {field: 'startTime', title: '开始时间', align: 'center'},
                {field: 'endTime', title: '结束时间', align: 'center'},
                {field: 'userType', title: '人群', align: 'center', templet: function(d){return d.userType==3?"教师":d.userType==4?"学生":"全部";}},
                {field: 'userType', title: '谁', align: 'center', templet: function(d){return d.schoolCode||d.squadCode||d.user_id;}},
                {title: '操作', width: 240, unresize: true, align: 'center',
                    templet: function (d) {
                        return '<a href="javascript:;" class="font-primary" lay-event="read">查看</a>';
                }}
            ]]
            , page: true
        });
        // 检索
        $("#search").click(function () {
            reloadTable(tableObj);
        });
        // 清除搜索条件
        $("#clear").click(function () {
            $("#list_form input").val('');
        });

        //表格头工具栏事件
        table.on('toolbar(mainList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    showDialog({
                        title: '发布新任务'
                        , template: 'add'
                        , tableObj: tableObj
                        , height:548
                        , saveUrl: context + '/api/eduTask/add'
                        , type: "post"
                        , dataType: 'json'
                    }); break;
                case 'myTask':
                    showDialog({
                        title: '我的任务'
                        , template: context + '/views/system/task/myTask.html'
                        , tableObj: tableObj
                        , width: 1100
                        , height: 548
                        // , saveUrl: context + '/api/eduTask/add'
                        // , type: "post"
                        // , dataType: 'json'
                    }); break;
                default: break;
            }
        });


        //表格内部操作按钮监听
        table.on('tool(mainList)', function (obj) { //注：tool是工具条事件名，mainList是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'read') {//编辑
                $.ajax({
                    url: context + '/api/eduTask/update?task_id='+data.task_id,
                    type: 'get',
                    success: function (r) {
                        if(r.success){
                            showAlert('阅读成功');
                            reloadTable(tableObj);
                        }
                    }
                });
            }
        });

    });
</script>
